feat: polymorphic helper for request body streaming#484
feat: polymorphic helper for request body streaming#484tank-bohr wants to merge 1 commit intoelixir-mint:mainfrom
Conversation
3b56627 to
a2a1dcc
Compare
|
You are treating H2 send window and sndbuf as two implementations of "how big should the next chunk be," but they're values from different layers that serve different purposes. The H2 send window is a contract with the peer, if we exceed it we get a protocol error, Mint checks it because violating it is a wire-level bug, not for performance or to avoid blocking. sndbuf is the size of the kernel send buffer. It's not a contract and no error if you "exceed" it. gen_tcp.send just blocks until the kernel drains enough bytes to accept more. For H1, sndbuf is the buffer's total capacity, not its current free space (unlike H2 windows). Send one sndbuf-sized chunk and it sits in the kernel buffer until the receiver ACKs, if we send a second one immediately and it blocks waiting for ACKs. Chunking by sndbuf only sizes the first send to fit an empty buffer, every send after that depends on how fast ACKs come back. For H2, the window can easily exceed sndbuf. When the window is bigger, sending up to it fills the kernel buffer and blocks anyway. The H2 code only guarantees protocol compliance, not non-blocking sends. For these reasons the proposed implementation is a leaky abstraction over H1 and H2. With the change in #483 users can implement streaming and it's up to the user to pick a chunk size that's appropriate for their application's needs. |
|
To elaborate on this a bit more and suggest a hopefully acceptable solution. The library should not pick the application chunk size. The user should pick a chunk size based on latency, memory, producer shape, backpressure model, and tolerance for blocking. Mint should only expose the protocol constraint. Given that, we can add a function user_chunk_size = 16_384
limit =
case Mint.HTTP.request_body_window(conn, ref) do
:infinity -> user_chunk_size
window -> min(user_chunk_size, window)
end |
Continues the discussion from the #477
Before
After
Wins:
stream_request_body/3protocol-agnostic